package fr.eisti.icc.data;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author clion
 */
@Entity
@Table(name="EMPRUNT")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Emprunt implements Serializable {

    @Id
    @GeneratedValue
    @Column(name="id")
    
    private int id;
    @OneToOne(cascade = {CascadeType.ALL}, orphanRemoval = false)
    @JoinColumn(name = "id_document")
    private Document document;
    @Column(name="dateDebutEmprunt")
    private String dateDebutEmprunt;
    @Column(name="jours")
    private int jours;
    @Column(name="chequeCaution")
    private boolean chequeCaution;

    @Column(name="emprunteur")
    private String emprunteur;

    public Emprunt(){

    }

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {

        return id;
    }

    public Emprunt( Document document, String dateDebutEmprunt, int jours, boolean chequeCaution, String emprunteur) {
     //   this.id2="1822"+Math.random();
        this.document = document;
        this.dateDebutEmprunt = dateDebutEmprunt;
        this.jours = jours;
        this.chequeCaution = chequeCaution;
        this.emprunteur = emprunteur;
    }

    public String getEmprunteur() {
        return emprunteur;
    }

    public void setEmprunteur(String emprunteur) {
        this.emprunteur = emprunteur;
    }


    public void setDocument(Document document) {
        this.document = document;
    }

  //  public String getId2() {
  //      return id2;
  //  }

   // public void setId2(String id2) {
  //      this.id2 = id2;
   // }

    public void setDateDebutEmprunt(String dateDebutEmprunt) {
        this.dateDebutEmprunt = dateDebutEmprunt;
    }

    public void setJours(int jours) {
        this.jours = jours;
    }

    public void setChequeCaution(boolean chequeCaution) {
        this.chequeCaution = chequeCaution;
    }

    public boolean isChequeCaution() {

        return chequeCaution;
    }

    public Document getDocument() {
        return document;
    }

    public String getDateDebutEmprunt() {
        return dateDebutEmprunt;
    }

    public int getJours() {
        return jours;
    }

    @Override
    public String toString() {
        return "Emprunt{" + "id=" + id + ", document=" + document.getId() + ",  emprunteur=" + emprunteur + "}\n";
    }

}
